package com.example.administrator.chesstest01;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/6/25.
 */
public class MyAdapter extends BaseAdapter {
    private ArrayList<RoomMessageItem> arrayList;
    private Context context;
    private LayoutInflater inflater;

    public MyAdapter(Context context, ArrayList<RoomMessageItem> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
        inflater = LayoutInflater.from(this.context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder ;
        if (null == convertView){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item,null);
            viewHolder.tvRoomId= (TextView) convertView.findViewById(R.id.tv_id);
            viewHolder.tvRoomName= (TextView)convertView.findViewById(R.id.tv_room_name);
            viewHolder.tvUserNumber= (TextView)convertView.findViewById(R.id.tv_user_number);
            convertView.setTag(viewHolder);}
        else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tvRoomId.setText("房间号"+arrayList.get(position).getRoomId());
        viewHolder.tvRoomName.setText("房间名"+arrayList.get(position).getRoomName());
        viewHolder.tvUserNumber.setText("玩家数"+arrayList.get(position).getUserNumber());

        return convertView;
    }
    class ViewHolder{

        TextView tvRoomId;
        TextView tvRoomName;
        TextView tvUserNumber;

    }
}
